﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcHorarios.Controllers
{
    public class HorarioController : Controller
    {
        private HorarioWS.HorariosClient proxy = new HorarioWS.HorariosClient(); 
        
        //
        // GET: /Horario/
    
        public ActionResult Index()
        {
            List<HorarioWS.Horario> horarios = proxy.ListarHorarios();
            return View(horarios);
        }

        //
        // GET: /Horario/Details/5

        public ActionResult Details(int id)
        {
            HorarioWS.Horario horarioObtenido = proxy.ObtenerHorario(id);
            return View(horarioObtenido);
        }

        //
        // GET: /Horario/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Horario/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                string fecIni = collection["fecIni"];
                string fecFin = collection["fecFin"];
                string dia = collection["dia"];
                string horas = collection["horas"];
                DateTime d= new DateTime();
                proxy.CrearHorario(d, d, dia, horas);

                return RedirectToAction("Index");
            }
            catch(Exception e)
            {
                ModelState.AddModelError(String.Empty, "Error: " + e.Message);
                return View();
            }
        }
        
        //
        // GET: /Horario/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Horario/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Horario/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Horario/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
